/**
 * Filename:utility.js
 * Used to define some utility functions.
 * 
 * @author Nonsenser
 * mail:n0nsenser@hotmail.com
 */

function CheckAllBoxes(the_form)
{
	var thisform = document.forms[the_form];
	for(var i=1;i<thisform.length;i++)
	{
		if((thisform.elements[i].tagName=="INPUT") && (thisform.elements[i].type=="checkbox"))
		{
			thisform.elements[i].checked = thisform.elements['0'].checked;
		}
	}
}
/*
 * This function implement extracts ip address stored with the format
 *xxx.xxx.xxx.xxx format in a the argument content.
 * Return:results as a array that contain the ip addresses.
 */
function ExtractIP(content)
{
	var ip_rexp = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+)/g;
	var temp = content.match(ip_rexp);
	var results = [];
	for(var i=0;temp[i];i++)
	{
		results.push(temp[i]);
	}
	return results;
}

function ExtractList(url,begin_str,end_str)
{
	var ajax = new Ajax();
	if (ajax.hreq.overrideMimeType) {
			ajax.hreq.overrideMimeType("text/html");
	}                                                     
	ajax.get(url,ShowHtml,false);
	
}

function loadJs(file){
    var scriptTag = document.getElementById('loadScript');
    var head = document.getElementsByTagName('head').item(0);
    if(scriptTag) head.removeChild(scriptTag);
    script = document.createElement('script');
    script.src = "../js/mi_"+file+".js";
    script.type = 'text/javascript';
    script.id = 'loadScript';
    head.appendChild(script);
}

function loadCss(file){
    var cssTag = document.getElementById('loadCss');
    var head = document.getElementsByTagName('head').item(0);
    if(cssTag) head.removeChild(cssTag);
    css = document.createElement('link');
    css.href = file;
    css.rel = 'stylesheet';
    css.type = 'text/css';
    css.id = 'loadCss';
    head.appendChild(css);
}

var cssfile = new Array();
cssfile[0] = "./skin/default/layout.css";
cssfile[1] = "./skin/1/layout.css";
var cssindex = 0;
function ChangeSkin()
{
	cssindex = 1 - cssindex;
	//alert(cssfile[cssindex]);
	loadCss(cssfile[cssindex]);
}